module Cip
  class Admin::UserSessionsController < Admin::ApplicationController
    skip_before_action :authenticate!

    def show
      redirect_to new_cip_admin_user_session_path
    end

    def new
      @user_session = UserSession.new
    end

    def create
      @user_session = UserSession.new(user_session_params.to_h)

      if @user_session.save
        redirect_to cip_admin_root_path
      else
        render :new
      end
    end

    def destroy
      current_user_session.destroy
      redirect_to new_cip_admin_user_session_path
    end

    private

    def user_session_params
      params.require(:cip_user_session).permit(:mobile, :password)
    end
  end
end
